<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<title></title>
		<script type="text/javascript" src="../../js/boot.js"></script>
	</head>

	<body>
		<div style="width:100%;height:14%;">
			<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
				<legend><span>查询条件</span></legend>
				<div id="queryForm" class="fieldset-body">
					<table class="form-table" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="form-label">
								<span>姓名：</span>
								<input name="userName" class="mini-textbox" style="width: 150px" />
								<input name="userName_link" value="like" class="mini-hidden" style="width: 150px" />
								<a class="mini-button" onclick="doSearch">查询</a>
								<a class="mini-button" iconCls="icon-edit" onclick="doEdit()">编辑</a>
							</td>
						</tr>
					</table>
				</div>
			</fieldset>

		</div>
		<div style="width:100%;height:86%;">
			<div class="mini-fit">
				<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" idField="instID" allowResize="true">
				</div>
			</div>
		</div>

		<!-- 计算需要显示的控件数量 -->
		<!-- 根据控件数量计算窗体的高度 -->
		<div id="detailWin" class="mini-window" title="" style="width:300px;height:220px;" showMaxButton="true" showCollapseButton="true" showShadow="true" showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
			<div id="detailForm" style="padding:10px;">
				<input class="mini-hidden" name="factorId">
				<table align="center">
					<tr>
						<td align="right">openId：</td>
						<td align="left"><input name="openId" class="mini-textbox" /></td>
					</tr>
					<tr>
						<td align="right">用户角色：</td>
						<td align="left"><input name="userType" class="mini-combobox" textField="name" valueField="id" data="userTypes" />
						</td>
					</tr>
				</table>
			</div>
			<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
				<a class="mini-button" iconCls="icon-save" onClick="doSave()">保存</a>
				<a class="mini-button" iconCls="icon-cancel" onClick="cancel()">取消</a>
			</div>
		</div>
	</body>

	<script type="text/javascript">
		userTypes = [{
			"id": "学生",
			"name": "学生"
		}, {
			"id": "家长",
			"name": "家长"
		}, {
			"id": "管理员",
			"name": "管理员"
		}];
		miniInit();

		var queryForm = new mini.Form("#queryForm");
		var detailForm = new mini.Form("#detailForm");
		var win = mini.get("detailWin");

		var datagrid = mini.get("datagrid");
		datagrid.set({
			url: http.getUrl("/weixin/user/page.do?admin=test"),
			columns: [{
				type: "indexcolumn"
			}, {
				field: "openId",
				width: 100,
				headerAlign: "center",
				allowSort: true,
				header: "openId"
			}, {
				field: "nickname",
				width: 100,
				headerAlign: "center",
				header: "昵称"
			}, {
				field: "country",
				width: 100,
				headerAlign: "center",
				allowSort: true,
				header: "国家"
			}, {
				field: "province",
				width: 100,
				headerAlign: "center",
				header: "省份"
			}, {
				field: "city",
				width: 100,
				headerAlign: "center",
				header: "城市"
			}, {
				field: "subscribeTime",
				width: 100,
				headerAlign: "center",
				dateFormat: "yyyy-MM-dd",
				header: "关注时间"
			}]
		});

		// 表单与表格绑定数据
		var db = new mini.DataBinding();
		db.bindForm("detailForm", datagrid);

		// doSearch();
		function doSearch() {
			var data = queryForm.getData(true, false);
			datagrid.load(data, null, miniui.showLoadErrorMessageBox);
		}

		function doEdit() {
			if(datagrid.getSelected()) {
				win.setTitle("修改机构数据");
				win.showAtPos('center', 'middle');
			} else {
				mini.alert("请选中需要修改的数据行", "提示", null);
			}
		}

		function doSave() {
			if(!detailForm.validate()) {
				return;
			}
			mini.mask({
				el: document.body,
				cls: 'mini-mask-loading',
				html: '数据保存中...'
			});
			var data = detailForm.getData();
			data.admin = "test";
			http.post("/weixin/user/saveUserType.do", data, function(page) {
				mini.unmask();
				win.hide();
				mini.alert("保存成功", "提示", null);
				datagrid.reload();
			});
		}

		function cancel() {
			win.hide();
		}
	</script>

</html>